Hey all, I just joined the forum! My name is Sam.
I have an assignment due in a few hours, and I can't seem to figure out why my C program won't read the last unsigned int.
On line 23, the last variable (unsigned int spartyCount = 0 isn't read. Once I enter the letter M in the second switch, once I exit out (by hitting Y and the Z), the printf doesn't count up the number of times I hit M.
The same thing happens for any int that's on the bottom of the list of integers. If wolvCount was on the bottom of the list, the letter W would not be counted into the last printf statement, either.
I have attached the C program file below.
Code:
#include <stdio.h>
/*
You shall fix the following program and the program must also do the following:
add up all of the times for Tigers, Red Wings, Pistons or school
add a new section called S
then ask for Grizzly, Wolverine or Sparty
At the end of the program:
print out how many for each catagory
Fix the problem with the dafault option
*/
int main( void )
{
char team;
unsigned int tigerCount = 0;
unsigned int wingCount = 0;
unsigned int pistCount = 0;
char team2;
unsigned int grizzCount = 0;
unsigned int wolvCount = 0;
unsigned int spartyCount = 0;
printf("Enter T for Tigers, R for Red Wings, or P for Pistons.\n");
printf("The loop will end once Z is entered.\n");
do
{
scanf("%s", &team);
printf("You entered team %c.\n", team);
switch(team)
{
case 'T':
printf("Tigers are da bomb.\n");
tigerCount++;
break;
case 'R':
printf("Red Wings are da bomb.\n");
wingCount++;
break;
case 'P':
printf("Piston are da bomb.\n");
pistCount++;
break;
case 'S':
printf("Enter G for Grizzly, W for Wolverine, or M for Sparty.\n");
printf("This loop will end once you enter Y.\n");
do
{
scanf("%s", &team2);
printf("You entered team %c.\n", team2);
switch(team2)
{
case 'G':
printf("Grizzlies are da bomb.\n");
grizzCount++;
break;
case 'W':
printf("Wolverines are da bomb.\n");
wolvCount++;
break;
case 'M':
printf("Spartans are da bomb.\n");
spartyCount++;
break;
case '\n':
case '\t':
case ' ':
break;
default:
printf("Please enter another valid character.\n");
break;
}
} while (team2 != 'Y');
printf("Enter T for Tigers, R for Red Wings, or P for Pistons.\n");
break;
case '\n':
case '\t':
case ' ':
break;
default:
printf("Please enter a valid character.\n");
break;
}
} while (team != 'Z');
printf("\n%u - Tigers %u - Red Wings %u - Pistons\n", tigerCount, wingCount, pistCount);
printf("And the other schools...\n");
printf("%u - Grizzlies %u - Wolverines %u - Spartans\n", grizzCount, wolvCount, spartyCount);
}